package cn.hnbjx.prepaid.utils;


import cn.hnbjx.prepaid.common.BusinessStatus;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data = "";

    public Result() {
    }

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(String msg, Object data) {
        this.code = 0;
        this.msg = msg;
        this.data = data;
    }

    public Result(Object data) {
        this.code = 0;
        this.msg = "success";
        this.data = data;
    }

    public static Result ok() {
        return new Result(0, "success", "");
    }

    public static Result ok(Object obj) {
        return new Result(0, "success", obj);
    }

    public static Result fail(BusinessStatus businessStatus) {
        return fail(businessStatus, businessStatus.getMessage());
    }

    public static Result fail(BusinessStatus businessStatus, String msg) {
        Result result = new Result();
        result.setCode(businessStatus.getCode());
        result.setMsg(msg);
        return result;
    }
}